import Vue from 'vue'
import Router from 'vue-router'
// import HelloWorld from '@/components/HelloWorld'
const bookcontent = () => import('pages/bookcontent.vue')
const booklist = () => import('pages/booklist.vue')
const bookcontentlist = () => import('pages/bookcontentlist.vue')
const newbook = () => import('pages/newbook.vue')
const login = () => import('pages/login.vue')
const originalPush = Router.prototype.push
Router.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(Router)
// const routerPush = Router.prototype.push
// Router.prototype.push = function push(location) {
//     return routerPush.call(this, location).catch(error=> error)
// }
export const defaultRouterMap = [
  { path: '/', redirect: '/index' },
  {
    path: '/index',
    component: booklist,
    name: 'index',
    meta: {
      title: '想看点小说',
      keepAlive: true // 需要被缓存
    }
  },
  {
    path: '/bookcontent/:contentid/:name/:title',
    component: bookcontent,
    name: 'bookcontent'
  },
  {
    path: '/bookcontentlist/:id/:name',
    component: bookcontentlist,
    name: 'bookcontentlist',
    meta: {
      title: '目录'
    }
  },
  {
    path: '/newbook',
    component: newbook,
    name: '新增'
  },
  {
    path: '/login',
    component: login,
    name: '登陆'
  },
  {
    path: '/foldnfly',
    component: () => import('pages/fly/foldnfly'),
    name: 'foldnfly',
    meta: {
      title: 'ineed.foldnfly'
    }
  },
  {
    path: '/searchNewBook',
    component: () => import('pages/searchNewBook'),
    name: 'searchNewBook',
    meta: {
      title: '查找新书'
    }
  }
]

export default new Router({
  mode: 'hash', // 去掉 # url锚点
  routes: defaultRouterMap
})
